package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;

/**
 * @author LIFF
 *     <p>增值服务选购
 */
public class OperationServicePriceAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

  @Override
  public String getValueDesc(KiteAttr attr, KiteInst inst, String value, AttrData data) {
    if (StringUtils.isEmpty(value)) {
      return null;
    }

    return Arrays.stream(value.split(","))
        .map(
            attrValue -> {
              // 对下拉框默认值操作
              KiteAttrValue kiteAttrValue = this.getKiteAttrByvalue(attr, attrValue);

              if (kiteAttrValue != null) {
                return kiteAttrValue.getAttrValueName();
              }
              return attr.getValue();
            })
        .collect(Collectors.joining(","));
  }
}
